package com.avocado.base.controller;


import com.avocado.base.dto.UserUpdatePasswordDto;
import com.avocado.base.service.UserService;
import com.avocado.commons.model.http.BaseResponse;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;


@Controller
@RequestMapping("/password/*")
public class PasswordController {

	private  final UserService userService;

	public PasswordController(UserService userService) {
		this.userService = userService;
	}


	@RequestMapping("/update")
	public @ResponseBody BaseResponse updatePassword(@RequestBody @Validated UserUpdatePasswordDto dto, Principal user)  throws Exception{

		userService.updatePassword(dto.getNewPassword(),user.getName());

		return BaseResponse.builder().status(1).message("操作成功!").build();
	}



}
